<template>
	<view>
		<!-- 支付宝 -->
		<block v-if="which == 0 && token">
			<view class="ipt-box z-padding-lr-32 z-margin-t-48">
				<text class="z-font-24 z-font-w">姓名</text>
				<view class="z-padding-lr-32 ipt z-margin-t-24">
					<input class="input" type="text" placeholder="输入支付宝姓名" v-model="info.alipay_name" />
				</view>
			</view>
			<view class="ipt-box z-padding-lr-32 z-margin-t-48">
				<text class="z-font-24 z-font-w">账号</text>
				<view class="z-padding-lr-32 ipt z-margin-t-24">
					<input class="input" type="text" placeholder="输入支付宝账号" v-model="info.alipay_account" />
				</view>
			</view>
		</block>

		<!-- 银行卡 -->
		<block v-if="which == 1 && token">
			<view class="ipt-box z-padding-lr-32 z-margin-t-48">
				<text class="z-font-24 z-font-w">姓名</text>
				<view class="z-padding-lr-32 ipt z-margin-t-24">
					<input class="input" type="text" placeholder="输入姓名" v-model="info.bank_user"/>
				</view>
			</view>
			<view class="ipt-box z-padding-lr-32 z-margin-t-48">
				<text class="z-font-24 z-font-w">开户行</text>
				<view class="z-padding-lr-32 ipt z-margin-t-24">
					<input class="input" type="text" placeholder="请输入开户行名称" v-model="info.bank_name"/>
				</view>
			</view>
			<view class="ipt-box z-padding-lr-32 z-margin-t-48">
				<text class="z-font-24 z-font-w">银行卡号</text>
				<view class="z-padding-lr-32 ipt z-margin-t-24">
					<input class="input" type="number" placeholder="请输入银行卡号" v-model="info.bank_card"/>
				</view>
			</view>
		</block>

		<!-- 按钮 -->
		<view class="order-btn-box">
			<view class="btn z-text-c theme-colors" @tap="save">确定</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			which: '',
			info: '',
			token: ''
		};
	},
	onLoad(options) {
		this.which = options.account,
		this.token = uni.getStorageSync('token')
		if (options) {
			uni.setNavigationBarTitle({
				title: options.account == 0 ? '支付宝账户' : '银行卡账户'
			});
		}
		this.getInfo();
	},
	methods: {
		// setInfo(e) {
		// 	let name = e.currentTarget.dataset.content;
		// 	this.info[name] = e.detail.value;
		// 	this.setData({
		// 		info: this.info
		// 	});
		// },
		save() {
			if (this.which == 0) {
				if (this.info.alipay_name.trim() === '') return this.util.toast('请输入支付宝姓名');
				if (this.info.alipay_account.trim() === '') return this.util.toast('请输入支付宝账号');
			}

			if (this.which == 1) {
				if (this.info.bank_user.trim() === '') return this.util.toast('请输入姓名');
				if (this.info.bank_name.trim() === '') return this.util.toast('请输入开户行');
				if (this.info.bank_card.trim() === '') return this.util.toast('请输入银行卡号');
			}

			this.http.post('index/updateuser', {
				...this.info,
				type: 'update'
			}).then((res) => {
				this.util.toast(res.msg);
				setTimeout(() => {
					this.util.back();
				}, 1000);
			});
		},
		getInfo() {
			this.http.get('index/updateuser').then((res) => {
				this.info = res.data
			});
		}
	}
};
</script>

<style>
.ipt-box {
	width: 622rpx;
	/* margin: auto; */
}
.ipt {
	width: 622rpx;
	height: 100rpx;
	background: #f5f7f9;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	opacity: 1;
}
.input {
	position: relative;
	top: 25rpx;
}
.order-btn-box {
	width: 750rpx;
	height: 180rpx;
	background: #ffffff;
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	opacity: 1;
	position: fixed;
	bottom: 0;
}
.btn {
	width: 686rpx;
	height: 98rpx;
	border-radius: 10rpx 10rpx 10rpx 10rpx;
	opacity: 1;
	line-height: 98rpx;
	margin: auto;
	margin-top: 14rpx;
	font-size: 30rpx;
	font-weight: bold;
	color: #ffffff;
}
</style>
